package leetcode._003;

import java.util.HashSet;

public class Solution02 {
    public int lengthOfLongestSubstring(String s) {
        int n = s.length();

        HashSet<Character> hashSet = new HashSet<>();
        int i = 0 ,j = 0, max = 0;
        while (i < n && j < n) {
            if (!hashSet.contains(s.charAt(j))) {
                hashSet.add(s.charAt(j++));
                max = max > j - i ? max : j - i;
            } else {
                hashSet.remove(s.charAt(i++));
            }
        }
        return max;

    }
}
